--读取脚本
local setKey = KEYS[1]
local members = redis.call('SMEMBERS', setKey)
local results = {}
local expiredKeys = {}

redis.log(redis.LOG_WARNING, KEYS[1])

for i, dataKey in ipairs(members) do
    local res = redis.pcall("GET", dataKey)
    if not res.err and redis.call("EXISTS", dataKey) == 1 then
        table.insert(results, res)
    else
        table.insert(expiredKeys, dataKey)
    end
end

if #expiredKeys > 0 then
    redis.call("SREM", setKey, unpack(expiredKeys))
end

return results
